﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMTP.Master" AutoEventWireup="true" CodeBehind="WorkingTime.aspx.cs" Inherits="SQT.tracnghiem.Admin.Accountant" %>

<%@ Import Namespace="DataAccess" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="../Ajax/JS/Accountant.js"></script>
    <script src="../Scripts/Chart.bundle.js"></script>
    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="main-admin" class="admin-df w3-row w3-light-grey">
        <header class="w3-padding w3-large w3-center w3-teal">KẾ TOÁN&nbsp;<i class="fa fa-angle-right"></i>&nbsp;GIỜ LÀM</header>
        <div id="ac1" class="acc w3-row">
            <div class="w3-col l7 w3-padding-left">
                <div class="w3-row w3-padding-top w3-padding-bottom">
                        <select class="accountant-select" id="ddl_staff">
                            <%foreach (TblManagerRole admin in new TblManagerRoleController().FetchAll().Where(x=>x.RoleId!=1))
                              { %>
                            <option value="<%=admin.RoleId %>"><%=admin.RoleName %></option>
                            <%} %>
                        </select>
                        <%--<select id="filteroption" class="accountant-select" disabled="disabled">
                            <option value="0" selected="selected">Theo tháng</option>
                            <option value="1">Theo ngày</option>
                        </select>--%>
                        <select id="ddl_select_month" class="accountant-select">
                            <%for (int i = 1; i <= 12; i++)
                              { %>
                            <%if (i == DateTime.Now.Month)
                              { %>
                            <option selected="selected" value="<%=i %>"><%=i %></option>
                            <%}
                              else
                              { %>
                            <option value="<%=i %>"><%=i %></option>
                            <%} %>

                            <%} %>
                        </select>
                        <select id="ddl_select_year" class="accountant-select">
                            <%for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 8; i--)
                              { %>
                            <option value="<%=i %>"><%=i %></option>
                            <%} %>
                        </select>
                    <div class="w3-col l6" id="filterday" style="display: none">
                        <%string date = DateTime.Now.Year.ToString();
                          if (DateTime.Now.Month < 10)
                          {
                              date += "-0";
                              date += DateTime.Now.Month.ToString();
                          }
                          else
                              date += "-" + DateTime.Now.Month.ToString();
                          if (DateTime.Now.Day < 10)
                          {
                              date += "-0";
                              date += DateTime.Now.Day.ToString();
                          }
                          else date += "-" + DateTime.Now.Day.ToString(); %>
                        <input class="accountant-date" id="date_from" type="date" value="<%=date %>" />
                        <span><i class="fa fa-arrow-right"></i></span>
                        <input class="accountant-date" id="date_to" type="date" value="<%=date %>" />
                    </div>
                    <a id="btn_search" class="w3-btn w3-teal" title="Tra cứu" style=""><i class="fa fa-search"></i></a>
                </div>
                <% %>
                <div id="working_Time_Area" class="accountant-table w3-row w3-white w3-card-2"></div>
                <div id="working_data_area" class="w3-hide"></div>
            </div>
            <div class="w3-col l5 w3-padding">
                <div class="w3-white w3-card-2">
                    <header class="w3-padding w3-center w3-teal">NHÂN VIÊN</header>
                    <ul class="w3-ul">
                        <li class="w3-padding w3-row w3-light-grey">
                            <div class="w3-col l2">
                                <span>Ảnh</span>
                            </div>
                            <div class="w3-col l6">
                                <span>Họ tên</span>
                            </div>
                            <div class="w3-col l4">
                                <span>Trang thái</span>
                            </div>
                        </li>
                    </ul>
                    <ul class="working-hour w3-ul">
                        <%foreach (TblManager admin in new TblManagerController().FetchAll().Where(x => x.Active == true))
                          {
                              if (admin.Role == 1)
                                  continue;
                        %>
                        <li class="w3-padding w3-row">
                            <div class="w3-col l2">
                                <img src="../Content/avatar/<%=admin.Avatar %>" class="w3-left w3-circle w3-margin-right" style="width: 40px; height: 40px" />
                            </div>
                            <div class="w3-col l6">
                                <span><%=admin.FullName %></span>
                            </div>
                            <div class="w3-col l4">
                                <%
                              var get_chk = new TblCheckManagerController().FetchAll().Where(x => x.ManagerId == admin.ManagerId && DateTime.Parse(x.CheckIn.ToString()).Date == DateTime.Now.Date).ToList();
                              if (get_chk.Count != 0)
                              { %>
                                <span class=" w3-text-teal"><i class="fa fa-smile-o"></i>&nbsp;Có mặt</span>
                                <%}
                              else
                              { %>
                                <span class=" w3-text-red"><i class="fa fa-frown-o"></i>&nbsp;Vắng</span>
                                <%} %>
                            </div>
                        </li>
                        <%} %>
                    </ul>
                </div>
            </div>
            <div class="w3-col l5 w3-padding-right w3-padding-bottom w3-padding-left w3-right">
                <div class="w3-white w3-card-2">
                    <header class="w3-padding w3-center w3-teal">
                        THỐNG KÊ GIỜ LÀM THÁNG
                        <select class="w3-teal w3-border" id="ddl_month" style="outline: none">
                            <%for (int i = 1; i <= 12; i++)
                              { %>
                            <%if (i == DateTime.Now.Month)
                              { %>
                            <option selected="selected" value="<%=i %>"><%=i %></option>
                            <%}
                              else
                              { %>
                            <option value="<%=i %>"><%=i %></option>
                            <%} %>

                            <%} %>
                        </select>
                        <select class="w3-teal w3-border" id="ddl_year" style="outline: none">
                            <%for (int i = DateTime.Now.Year; i >= DateTime.Now.Year - 10; i--)
                              { %>
                            <option value="<%=i %>"><%=i %></option>
                            <%} %>
                        </select>
                        <a id="btn_search_month" class="w3-teal w3-border w3-btn" style="outline: none" title="Tra cứu" style="margin-bottom: 3px"><i class="fa fa-search"></i></a>
                    </header>
                    <ul class="w3-ul">
                        <li class="w3-padding w3-row w3-light-grey">
                            <div class="w3-col l2">
                                <span>Ảnh</span>
                            </div>
                            <div class="w3-col l6">
                                <span>Họ tên</span>
                            </div>
                            <div class="w3-col l4">
                                <span>Tổng số giờ</span>
                            </div>
                        </li>
                    </ul>
                    <ul class="working-hour w3-ul" id="report_time_staff">
                        <%foreach (TblManager admin in new TblManagerController().FetchAll().Where(x => x.Role != 1 && x.Active == true))
                          {
                              int hour = 0, minute = 0;
                              foreach (TblCheckManager chk in new TblCheckManagerController().FetchAll().Where(x => x.ManagerId == admin.ManagerId && DateTime.Parse(x.CheckIn.ToString()).Month == DateTime.Now.Month && x.Accept == true))
                              {
                                  if (chk.CheckOut != null)
                                  {
                                      if (DateTime.Parse(chk.CheckOut.ToString()).Hour >= DateTime.Parse(chk.CheckIn.ToString()).Hour)
                                      {
                                          hour += DateTime.Parse(chk.CheckOut.ToString()).Hour - DateTime.Parse(chk.CheckIn.ToString()).Hour;
                                      }
                                      else
                                      {
                                          hour += 24 - DateTime.Parse(chk.CheckIn.ToString()).Hour + DateTime.Parse(chk.CheckOut.ToString()).Hour;
                                      }

                                      if (DateTime.Parse(chk.CheckIn.ToString()).Minute <= DateTime.Parse(chk.CheckOut.ToString()).Minute)
                                      {
                                          minute += DateTime.Parse(chk.CheckOut.ToString()).Minute - DateTime.Parse(chk.CheckIn.ToString()).Minute;
                                      }
                                      else
                                      {
                                          minute += 60 - DateTime.Parse(chk.CheckIn.ToString()).Minute + DateTime.Parse(chk.CheckOut.ToString()).Minute;
                                      }
                                  }
                              }
                              if (minute >= 60)
                              {
                                  int temp = minute / 60;
                                  hour += temp;
                                  minute = minute - (temp * 60);
                              }
                        %>
                        <li class="w3-padding w3-row">
                            <div class="w3-col l2">
                                <img src="../Content/avatar/<%=admin.Avatar %>" class="w3-left w3-circle w3-margin-right" style="width: 40px; height: 40px" />
                            </div>
                            <div class="w3-col l6">
                                <span><%=admin.FullName %></span>
                            </div>
                            <div class="w3-col l4">
                                <span><%=hour %>h<%=minute %>p</span>
                            </div>
                        </li>
                        <%} %>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <script src="../Scripts/loadbar.js"></script>
</asp:Content>
